import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)
// 路由重复问题
// const originalPush = VueRouter.prototype.push
// VueRouter.prototype.push = function push (location) {
//     return originalPush.call(this, location).catch(err => err)
// }
const Layout = () => import('@/layout')
export const constantRoutes = [{
    path: '/',
    redirect: '/web/index',
    hidden: true
}, {
    path: '/index',
    redirect: '/web/index',
    hidden: true
}, {
    path: '/index.html',
    redirect: '/web/index',
    hidden: true
}, {
    path: '/web',
    redirect: '/web/index',
    hidden: true
}, {
    path: '/404',
    name: '404',
    meta: {
        title: 'Oops～，我崩溃了！找不到你想要的页面了!'
    },
    component: () => import('@/views/error/404'),
    hidden: true
}, {
    path: '/401',
    name: '401',
    meta: {
        title: 'Oops～，我崩溃了！你没有操作权限!'
    },
    component: () => import('@/views/error/401'),
    hidden: true
}, {
    path: '/web/login',
    name: 'Login',
    component: () => import('@/components/Login'),
    meta: {
        title: '登录'
    },
    hidden: true
}, {
    path: '/web',
    component: () => import('@/views/Home'),
    hidden: true,
    children: [{
        path: 'index',
        name: 'Index',
        component: () => import('@/components/Index'),
        meta: {
            title: '首页'
        }
    }, {
        path: 'blog/:id',
        name: 'Blog',
        component: () => import('@/components/Blog'),
        meta: {
            title: '博客详情'
        }
    }, {
        path: 'search/blog',
        name: 'SearchBlog',
        component: () => import('@/components/SearchBlog'),
        meta: {
            title: '全文检索'
        }
    }, {
        path: 'categories',
        name: 'Charts',
        component: () => import('@/views/category/charts'),
        meta: {
            title: '分类'
        }
    }, {
        path: 'categories/:cate',
        name: 'CateList',
        component: () => import('@/views/category/list'),
        meta: {
            title: '分类'
        }
    }, {
        path: 'archives',
        name: 'Archives',
        component: () => import('@/views/archives'),
        meta: {
            title: '归档'
        }
    }, {
        path: 'about',
        name: 'About',
        component: () => import('@/views/about'),
        meta: {
            title: '关于我'
        }
    }]
}];
export const asyncRoutes = [{
    path: '/admin',
    name: 'Layout',
    redirect: '/admin/dashboard',
    component: Layout,
    children: [{
        path: 'dashboard',
        name: 'Dashboard',
        component: () => import('@/views/admin/dashboard'),
        meta: { title: '控制台', icon: 'dashboard', affix: true }
    }]
}, {
    path: '/admin/blogs',
    name: 'Blog',
    redirect: '/admin/blogs',
    component: Layout,
    meta: {
        title: '博客管理', icon: 'example'
    },
    children: [{
        path: '/admin/blogs',
        name: 'Blogs',
        component: () => import('@/components/admin/blog/Blogs'),
        meta: {
            title: '博客列表',
            icon: 'log'
        }
    }, {
        path: '/admin/blog/add',
        name: 'AddBlog',
        component: () => import('@/components/admin/blog/AddBlog'),
        meta: {
            title: '写博客', icon: 'stats2'
        }
    }]
}, {
    path: '/admin/types',
    name: 'Type',
    redirect: '/admin/types',
    component: Layout,
    meta: {
        title: '分类管理', icon: 'repo'
    },
    children: [{
        path: '/admin/types',
        name: 'Types',
        component: () => import('@/components/admin/type/Types'),
        meta: {
            title: '分类列表', icon: 'repo'
        }
    }]
}, {
    path: '/admin/logs',
    name: 'Log',
    redirect: '/admin/logs',
    component: Layout,
    meta: {
        title: '日志管理', icon: 'configure'
    },
    children: [{
        path: '/admin/logs',
        name: 'Logs',
        component: () => import('@/components/admin/log/Logs'),
        meta: {
            title: '操作日志', icon: 'admin'
        }
    }, {
        path: '/admin/logs/login',
        name: 'LoginLogs',
        component: () => import('@/components/admin/log/LoginLogs'),
        meta: {
            title: '登入日志'
        }
    }]
}];
const createRouter = () => new VueRouter({
    mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
})
const router = createRouter()

export function resetRouter () {
    const newRouter = createRouter()
    router.matcher = newRouter.matcher // reset router
}

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (location) {
    return originalPush.call(this, location).catch(err => err)
}
export default router
